package AlexDB.Test;

import java.io.IOException;
import java.util.Scanner;

import AlexDB.MDB.Persistence;
import AlexDB.Resolver.Resolve;
import AlexDB.Resolver.ResolveFactory;

public class Interactive {
    public static void main(String[] args) throws Exception {

        Persistence.readFromListProfile();
        boolean isRun = true;
        Scanner sc = new Scanner(System.in);
        while (isRun) {
            var command = sc.nextLine();
            if (command.equals("exit")) {
                Persistence.writeDbMapProfile();
                System.exit(0);
            } else if (command != null && command != "") {
                try {
                    var resolve = ResolveFactory.initialized().CreateResolve();
                    Object[] commandArgs = resolve.resolveArgs(command);
                    var result = resolve.resolveCommand(commandArgs).commandExecute(commandArgs);
                    var deresolveString = "";
                    if (result != null)
                        deresolveString += Resolve.deresolveResultToString(result);
                    System.out.println(deresolveString);
                } catch (Exception e) {
                    // System.out.println(e.getMessage());
                }

            }
        }
    }
}
